package team.fivez.defaultmanage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.fivez.defaultmanage.domain.Result;
import team.fivez.defaultmanage.mediumDomain.CompletedDefaultApplication;
import team.fivez.defaultmanage.service.DefaultApplicationService;
import team.fivez.defaultmanage.utils.Utils;
@CrossOrigin
@RestController
@RequestMapping("/defaultApplication")
public class DefaultApplicationController {

    private final DefaultApplicationService defaultApplicationService;


    @Autowired
    public DefaultApplicationController(DefaultApplicationService defaultApplicationService) {

        this.defaultApplicationService = defaultApplicationService;
    }

    //增加申请单
    @PostMapping("/addNewApplication")
    public Result addNewApplication(@RequestBody CompletedDefaultApplication completedDefaultApplication) throws InterruptedException {
        return Utils.success(defaultApplicationService.addNewDefaultApplication(completedDefaultApplication));
    }


    //申请人的默认界面
    @GetMapping("/applicantAll")
    public Result applicantAll(@RequestParam("applicantAccount") String applicantAccount){
        return Utils.success(defaultApplicationService.listSelectedCustomerByApplicant(applicantAccount));
    }

    //审核人更改审核状态（同意）
    @GetMapping("/agree")
    public Result agreeApplication(@RequestParam("applicationNumber") String applicationNumber,
                               @RequestParam("approverAccount") String approverAccount){
        return Utils.success(defaultApplicationService.updateStatus(1,applicationNumber,approverAccount));
    }

    //审核人更改审核状态（驳回）
    @GetMapping("/disagree")
    public Result disagreeApplication(@RequestParam("applicationNumber") String applicationNumber,
                               @RequestParam("approverAccount") String approverAccount){
        return Utils.success(defaultApplicationService.updateStatus(2,applicationNumber,approverAccount));
    }

    //申请人按照客户名进行查询
    @GetMapping("/applicantSearchByName")
    public Result getApplicantListByName(@RequestParam("applicantAccount") String applicantAccount,
                                         @RequestParam("customerName") String customerName){
        return Utils.success(defaultApplicationService.listSelectedCustomerByApplicantAndCustomerName(applicantAccount,
                customerName));
    }

    //申请人按照未审核进行查询
    @GetMapping("/applicantSearchByStatusZero")
    public Result getApplicantListByZero(@RequestParam("applicantAccount") String applicantAccount){
        return Utils.success(defaultApplicationService.listSelectedCustomerByApplicantAndStatus(applicantAccount,0));
    }

    //申请人按照已同意进行查询
    @GetMapping("/applicantSearchByStatusOne")
    public Result getApplicantListByOne(@RequestParam("applicantAccount") String applicantAccount){
        return Utils.success(defaultApplicationService.listSelectedCustomerByApplicantAndStatus(applicantAccount,1));
    }

    //申请人按照已驳回进行查询
    @GetMapping("/applicantSearchByStatusTwo")
    public Result getApplicantListByTwo(@RequestParam("applicantAccount") String applicantAccount){
        return Utils.success(defaultApplicationService.listSelectedCustomerByApplicantAndStatus(applicantAccount,2));
    }

    //审核人默认界面
    @GetMapping("/allList")
    public Result getAllList(){
        return Utils.success(defaultApplicationService.listApplication());
    }

    //审核人按照名字进行查询
    @GetMapping("/searchByName")
    public Result getListByName(@RequestParam String customerName){
        return Utils.success(defaultApplicationService.listApplicationByCustomerName(customerName));
    }

    //审核人按照未审核进行查询
    @GetMapping("/searchByStatusZero")
    public Result getListByZero(){
        return Utils.success(defaultApplicationService.listApplicationByStatus(0));
    }

    //审核人按照已同意进行查询
    @GetMapping("/searchByStatusOne")
    public Result getListByOne(){
        return Utils.success(defaultApplicationService.listApplicationByStatus(1));
    }

    //审核人按照已驳回进行查询
    @GetMapping("/searchByStatusTwo")
    public Result getListByTwo(){
        return Utils.success(defaultApplicationService.listApplicationByStatus(2));
    }




}
